package com.telchina.model.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.telchina.common.utils.uuid.Seq;
import com.telchina.model.entity.TModelAttribute;
import com.telchina.model.entity.TModelControl;
import com.telchina.model.mapper.TModelAttributeMapper;
import com.telchina.model.mapper.TModelControlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

import com.telchina.model.entity.TModelManage;
import com.telchina.model.mapper.TModelManageMapper;
import com.telchina.model.service.ITModelManageService;
import org.springframework.transaction.annotation.Transactional;


/**
 * 设备模型(TModelManage)表服务实现类
 *
 * @author 郝振
 * @since 2023-06-17 17:00:50
 */
@Service("tModelManageService")
public class TModelManageServiceImpl extends ServiceImpl<TModelManageMapper, TModelManage> implements ITModelManageService {

    @Autowired
    private TModelManageMapper tModelManagemapper;
    @Autowired
    private TModelAttributeMapper tModelAttributeMapper;
    @Autowired
    private TModelControlMapper tModelControlMapper;

    /**
     * 查询设备模型列表
     *
     * @param tModelManage 筛选条件
     */
    public List<TModelManage> selectTModelManageList(TModelManage tModelManage) {
        return tModelManagemapper.selectTModelManageList(tModelManage);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(TModelManage entity) {
        boolean result = super.save(entity);
        for (TModelAttribute equipmentParameter : entity.getEquipmentParameters()) {
            equipmentParameter.setId(Seq.getId());
            equipmentParameter.setModelId(entity.getId());
            tModelAttributeMapper.insert(equipmentParameter);
        }
        for (TModelAttribute monitoringAttribute : entity.getMonitoringAttribute()) {
            monitoringAttribute.setId(Seq.getId());
            monitoringAttribute.setModelId(entity.getId());
            tModelAttributeMapper.insert(monitoringAttribute);
        }
        for (TModelControl control : entity.getControl()) {
            control.setId(Seq.getId());
            control.setModelId(entity.getId());
            tModelControlMapper.insert(control);
        }
        return result;
    }
}
